<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="layout" content="main" />
    <title>Edit Person</title>
  </head>
  <body>
    <div class="nav">
      <span class="menuButton"><a class="home" href="${resource(dir:'')}">Home</a></span>
      <span class="menuButton"><g:link class="list" action="list">Person List</g:link></span>
      <span class="menuButton"><g:link class="create" action="create">New Person</g:link></span>
      <span class="menuButton">
	<g:link class="vacations" action="vacationList" id="${fieldValue(bean:personInstance,field:'id')}">
	  ${personInstance.lastName} vacations
	</g:link>
      </span>
    </div>

    <div class="body">
      <h1>Edit Person</h1>

      <g:if test="${flash.message}">
        <div class="message">${flash.message}</div>
      </g:if>

      <g:hasErrors bean="${personInstance}">
        <div class="errors">
          <g:renderErrors bean="${personInstance}" as="list" />
        </div>
      </g:hasErrors>

      <g:form method="post" enctype="multipart/form-data">
        <input type="hidden" name="id" value="${personInstance?.id}" />
        <input type="hidden" name="version" value="${personInstance?.version}" />
        <div class="dialog">
          <table>
            <tbody>
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="name">Name:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'name','errors')}">
                  <input type="input" id="name" name="name" value="${fieldValue(bean:personInstance, field:'name')}" />
                </td>
              </tr> 
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="lastName">Last Name:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'lastName','errors')}">
                  <input type="text" id="lastName" name="lastName" value="${fieldValue(bean:personInstance, field:'lastName')}" />
                </td>
              </tr> 
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="telephone">Telephone:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'telephone','errors')}">
                  <input type="text" id="telephone" name="telephone" value="${fieldValue(bean:personInstance,field:'telephone')}"/>
                </td>
              </tr> 
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="email">Email:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'email','errors')}">
                  <input type="text" id="email" name="email" value="${fieldValue(bean:personInstance,field:'email')}"/>
                </td>
              </tr> 
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="birthday">Birthday:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'birthday','errors')}">
		  <input class="datepicker-field" id="birthday-datepicker" type="text" name="birthday" value="${personInstance?.birthday}"/>
                </td>
              </tr> 
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="personalIdNumber">Personal ID Number:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'personalIdNumber','errors')}">
                  <input type="text" id="personalIdNumber" name="personalIdNumber" value="${fieldValue(bean:personInstance,field:'personalIdNumber')}"/>
                </td>
              </tr> 
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="nip">Nip:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'nip','errors')}">
                  <input type="text" id="nip" name="nip" value="${fieldValue(bean:personInstance,field:'nip')}"/>
                </td>
              </tr> 
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="accountNumber">Account Number:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'accountNumber','errors')}">
                  <input type="text" id="accountNumber" name="accountNumber" value="${fieldValue(bean:personInstance,field:'accountNumber')}"/>
                </td>
              </tr>              

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="cv">Current CV:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'cvFilepath','errors')}">
		  <g:if test="${personInstance.cvFilepath}">
		    <a href="${g.createLink(controller: 'person', action: 'downloadCV', id: personInstance.id)}">
		      ${personInstance.getCVFileName()}
		    </a>
		  </g:if>
		  <g:else>
                    <label type="text" id="current-cv" name="current-cv">< there is no CV file yet ></label>
		  </g:else>
                </td>
              </tr>

              <tr class="prop">
                <td valign="top" class="name">
                  <label for="cv">CV:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'cvFilepath','errors')}">
                  <input type="file" id="cv" name="cv" value="${fieldValue(bean:personInstance,field:'cvFilepath')}"/>
                </td>
              </tr> 
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="country">Country:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'country','errors')}">
                  <input type="text" id="country" name="country" value="${fieldValue(bean:personInstance,field:'country')}"/>
                </td>
              </tr> 
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="city">City:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'city','errors')}">
                  <input type="text" id="city" name="city" value="${fieldValue(bean:personInstance,field:'city')}"/>
                </td>
              </tr> 
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="streetNumber">Street Number:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'streetNumber','errors')}">
                  <input type="text" id="streetNumber" name="streetNumber" value="${fieldValue(bean:personInstance,field:'streetNumber')}"/>
                </td>
              </tr> 
              
              <tr class="prop">
                <td valign="top" class="name">
                  <label for="postalCode">Postal Code:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean:personInstance,field:'postalCode','errors')}">
                  <input type="text" id="postalCode" name="postalCode" value="${fieldValue(bean:personInstance,field:'postalCode')}"/>
                </td>
              </tr> 
              
            </tbody>
          </table>
        </div>

        <div class="buttons">
          <span class="button">
	    <g:actionSubmit class="save" value="Update" />
	  </span>
          <span class="button">
	    <g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete" />
	  </span>
        </div>
      </g:form>
    </div>
  </body>
</html>
